package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig>
    implements ApArticleConfigService {

    /**
     * 上下架的修改业务
     * @param map
     */
    @Override
    public void updateByIsDown(Map map) {
        Long articleId = (Long) map.get("articleId");
        Integer enable = (Integer) map.get("enable");

        boolean isDown = true;
        if(enable == 1){
            isDown = false;// 上架
        }

        this.update(Wrappers.<ApArticleConfig>lambdaUpdate()
                .set(ApArticleConfig::getIsDown,isDown)
                .eq(ApArticleConfig::getArticleId,articleId)
        );
    }
}
